<?php
include('../includes/common.php');
if ($islogin2 == 1) { } else exit("<script language='javascript'>window.location.href='./login.php';</script>");
?>

<?php
$act = isset($_GET['act']) ? daddslashes($_GET['act']) : null;
$uid = $userrow['id'];
@header('Content-Type: application/json; charset=UTF-8');
switch ($act) {
    case 'getInfo': //查看宿舍详细信息
        $id = intval($_GET['id']);
        $rs = $conn->query("select * from dorm_list where id='$id' limit 1");
        if (!$rs)
            exit('{"code":-1,"msg":"当前宿舍不存在！"}');
        $res = $rs->fetch_assoc();
        if ($res['state'] == 1) {
            $state = '正常';
        } else {
            $state = '封禁';
        }
        $result = array("code" => 0, "msg" => "succ", "id" => $res['id'], "uid" => $res['uid'],  "state" => $state,  "remarks" => $res['remarks'],  "name" => $res['name'], "money" => $res['money'], "addtime" => $res['addtime']);
        exit(json_encode($result));
        break;
    case 'delSelect': //宿舍全选删除
        $id = explode('&', $_POST['str']);
        $i = 0;
        while ($i < count($id)) {
            $conn->query("delete from dorm_list where id = '$id[$i]'");
            $i++;
        }
        $result = array("code" => 0);
        exit(json_encode($result));
        break;
    case 'upSelect': //宿舍全选修改
        $id = explode('&', $_POST['str']);
        $i = 0;
        $name = $_GET['name'];
        while ($i < count($id)) {
            $conn->query("update dorm_list set name = '$name' where id = '$id[$i]'");
            $i++;
        }
        $result = array("code" => 0);
        exit(json_encode($result));
        break;
    case 'delSelect2': //记录全选删除
        $id = explode('&', $_POST['str']);
        $i = 0;
        while ($i < count($id)) {
            $conn->query("delete from rmb_list where id = '$id[$i]'");
            $i++;
        }
        $result = array("code" => 0);
        exit(json_encode($result));
        break;
}
